// 计分板
class ScorePanel {
    // 分数
    score: number = 0
    scoreElement: HTMLElement

    // 等级
    level: number = 1
    levelElement: HTMLElement

    // 最大等级
    maxLevel: number
    // 升级的分数
    upScore: number

    /**
     * 默认值
     * @param maxLevel 最大等级
     * @param upScore 升级的分数
     */
    constructor(maxLevel: number = 10, upScore: number = 10) {
        this.maxLevel = maxLevel
        this.upScore = upScore
        this.scoreElement = document.getElementById("score")!
        this.levelElement = document.getElementById("level")!
    }

    // 分数+
    addScore(): void {
        this.score++
        this.scoreElement.innerHTML = this.score + ''
        // 如果分数是 "升级的分数" 的倍数就升级
        if (this.score % this.upScore === 0) {
            this.levelUp()
        }
    }

    // 提升等级
    levelUp(): void {
        if (this.level < this.maxLevel) {
            this.level++
            this.levelElement.innerHTML = this.level + ''
        }
    }
}

export default ScorePanel